trigger setHospitalManager on User (after update) {
    map<id,user> umap=new map<id,user>();
    for(user u:trigger.new){
        if(trigger.oldmap.get(u.id).managerid != u.managerid){
            umap.put(u.id,u);
        }
    }
    
    if(umap.size()>0){
        list<hospital__c> hosl=[select id,ownerid from hospital__c where ownerid in:umap.keyset()];
        for(hospital__c hos:hosl){
            hos.manager__c=umap.get(hos.ownerid).managerid;
        }
        update hosl;
    }
    
}